package com.wgs.onomastici;

import java.util.ArrayList;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListaContatti extends AbstractBaseActivity implements OnClickListener {

	

	private ListView contatti;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lista_contatti);
		Resources res = getResources();
		setInfoMessage(res.getString(R.string.info_msg_listacontatti));
		
		
		contatti = (ListView) findViewById(R.id.contact_list);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_lista_contatti, menu);
		return true;
	}
	
	
	@Override
	protected void onStart() {
		super.onStart();
		
		Bundle bundle = getIntent().getExtras();
		ArrayList<String> contactList=bundle.getStringArrayList("contact");
		
		ListAdapter adapter = new ArrayAdapter<String>(this,R.layout.contact_item, contactList);
		
		
		contatti.setAdapter(adapter);

		contatti.setOnItemClickListener(new OnItemClickListener() {
            @Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {
                
                String item = ((TextView)view).getText().toString();
                
                String[] par=item.split("\n");
                
                Bundle bundle=new Bundle();
				bundle.putString("numeri", par[1]);
				Intent messaggio = new Intent(getApplicationContext(),
						InviaSms.class);
				messaggio.putExtras(bundle);
				startActivity(messaggio);
                  
            }
        });
		
		
	}

	@Override
	public void onClick(View v) {}
	
	

}
